<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #demo {
            width: 200px;
            height: 200px;
            background-color: #6ff;
            margin: 50px;
        }
    </style>
</head>

<body>
    <div id="demo" class="one two three" title="hello" data-id="0" data-msg="你好" asd="asd">
        <span>hello</span>
    </div>
</body>
<script>
    var wrap = document.getElementById("demo")


    // 获取非行内样式  

    // 常规浏览器(IE8以及一下不支持):
    // window.getComputedStyle(ele)   传入一个DOM元素,返回该元素css样式形成的对象 (内部 外部 内联 默认)   => {width:"200px", height:"200px"}
    // console.log(window.getComputedStyle(demo));
    // console.log(window.getComputedStyle(demo).width);
    // console.log(window.getComputedStyle(demo).height);
    // console.log(window.getComputedStyle(demo).backgroundColor);
    // console.log(window.getComputedStyle(demo).marginLeft);
    // console.log(window.getComputedStyle);

    // IE低版本:
    // console.log(demo.currentStyle);
    // console.log(demo.currentStyle.width);
    // console.log(demo.currentStyle.height);


    // 兼容写法

    // if (window.getComputedStyle) {  //常规浏览器
    //     // console.log(window.getComputedStyle(demo));
    //     console.log(window.getComputedStyle(demo).width);
    // } else {  // IE低版本
    //     // console.log(demo.currentStyle);
    //     console.log(demo.currentStyle.width);
    // }


    function getStyle(ele, key) {
        if (window.getComputedStyle) {
            return window.getComputedStyle(ele)[key]
        } else {
            return ele.currentStyle[key]
        }
    }

    console.log(getStyle(demo, "width"))
    console.log(parseFloat(getStyle(demo, "width")))


</script>

</html>